package com.google.code.swingonfire;

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Transparency;
import java.awt.image.BufferedImage;

public class GraphicsUtils
{

    private GraphicsUtils()
    {
        super();
    }

    public static GraphicsEnvironment getGraphicsEnvironment()
    {
        return GraphicsEnvironment.getLocalGraphicsEnvironment();
    }

    public static GraphicsConfiguration getGraphicsConfiguration()
    {
        return getGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    }

    public static BufferedImage createCompatibleImage(int width, int height, boolean transparency)
    {
        return getGraphicsConfiguration().createCompatibleImage(width, height,
            (transparency) ? Transparency.TRANSLUCENT : Transparency.OPAQUE);
    }

    public static void clear(Graphics graphics, int width, int height)
    {
        Graphics2D g = (Graphics2D) graphics.create();

        g.setComposite(AlphaComposite.Clear);
        g.fillRect(0, 0, width, height);
    }

}
